package com.lagou.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Calendar;

/**
 * @author Mrwg
 * @date 2020/4/22
 * @description
 */
@RestController
@Slf4j
public class LoginController {
    @Value("${server.port}")
    private  String port;
    @GetMapping("/toLoginPage")
    public String toLoginPage(Model model,HttpServletRequest req, HttpServletResponse resp) throws IOException {

        log.info("===========================================>当前服务器端口：port"+port);
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        if ("admin".equalsIgnoreCase(req.getParameter("username")) && "admin".equalsIgnoreCase(req.getParameter("password"))) {
            HttpSession session = req.getSession();
            session.setAttribute("loginUser", "admin");
            resp.sendRedirect("/index");
            return "client/index";
        }else {
            return "login";
        }
    }
}
